
const app = getApp();

Component({
    /**
     * 组件的属性列表
     */
    properties: {
    },

    /**
     * 组件的初始数据
     */
    data: {
        aquariumId: wx.getStorageSync('userAquariumList')[wx.getStorageSync('curIndex')],
        // 是否弹出日期选择
        selected: false,

        //显示当前日期,
        showDate: '',

        //选择的日期时间戳
        value:Number,

        //  日期选择器的属性
        currentDate: new Date().getTime(),
        maxDate: new Date().getTime(),
        formatter(type, value) {
            if (type === 'year') {
                return `${value}年`;
            }
            if (type === 'month') {
                return `${value}月`;
            }
            return value;
        },


    },

    /**
     * 组件的方法列表
     */
    methods: {

        selectTime() {
            this.setData({
                selected: !this.data.selected
            })
        },

        onClose() {

            wx.setStorageSync('selectedDate', this.data.value)

            wx.reLaunch({
              url: '/pages/index/index?selectIndex=3',
            })

        },


        onInput(event) {
            this.setData({
                value: event.detail,
            });

        },

        addAquarium() {
            wx.redirectTo({
                url: '../../pages/index/index?selectIndex=4',
            })
        },
    },

    lifetimes: {
        attached() {
            //查看缓存中设置的日期
            let selectDate = Number(wx.getStorageSync('selectedDate'));
            let time =new Date(selectDate)

            console.log("缓存中选择了的日期为："+time)

            //如果没有设置日期，则用当前日期
            if (!selectDate) {
                console.log("没有传参数给waterMes")
               time = new Date()
                this.setData({
                    showDate:time.getFullYear() + " 年 " + (time.getMonth() + 1) + " 月 " + time.getDate() + " 日 ",
                    value: time.getTime,
                    currentDate:time.getTime
                })
                //往缓存中设置当前日期
                wx.setStorageSync('selectedDate', time.getTime())
               
            }else{
                //如果设置了日期
                this.setData({
                    showDate:time.getFullYear() + " 年 " + (time.getMonth() + 1) + " 月 " + time.getDate() + " 日 ",
                    value:time.getTime(),
                    currentDate:time.getTime()
                })
            }

        }

    }

})
